import { resolve } from 'path';
import singlePage from 'koa-single-page';

const spaFn = singlePage(resolve(__dirname, '../public'), {
  index: 'index.html',
});

export default () =>
  async function (ctx, next) {
    if (ctx.request.url.startsWith('/api')) {
      await next();
    } else {
      await spaFn(ctx, next);
    }
  };
